#ifndef BUFFER_H
#define BUFFER_H

#include <vector>
#include <stdio.h>
typedef unsigned char byte;

extern bool g_Verbal;

class Buffer  
{
public:
	Buffer(int Size);
	Buffer(FILE* file);
	~Buffer();
	Buffer& operator=(const Buffer& other);

	bool Write(FILE* file);

	void Reset(bool Erase=false)
	{
		m_CurrPos = 0;
		if (Erase)
			m_UsedSize = 0;
	}

	void PutByte(byte c);
	void PutShort(unsigned short c,bool Invert=false);
	void PutLong(unsigned long c,bool Invert=false);
	void PutFloat(float c);
	void PutString(std::string S);

	byte			GetByte() const;
	unsigned short	GetShort(bool Invert=false) const;
	unsigned long	GetLong(bool Invert=false) const;
	float			GetFloat() const;
	std::string		GetString() const;

	void ChangePos(int NewPos)
	{
		if (NewPos==-1)
			m_CurrPos = m_UsedSize;
		else
			m_CurrPos = NewPos;
	}

	byte* GetBuffer()
	{
		return &m_Data.front();
	}

	int GetUsedSize()
	{
		return m_UsedSize;
	}
	int GetRemainingSize()
	{
		return m_UsedSize - m_CurrPos;
	}

	void SetUsedSize(int Size)
	{
		m_UsedSize = Size;
	}
	unsigned int GetMaxSize() {return m_TotalSize;};

	virtual void WriteTo(Buffer& other, int Size = -1);

	bool HasMore() {return m_CurrPos < m_UsedSize;}

	byte GetAt(int Index) {return m_Data[Index];};

	int GetCurrPos() {return m_CurrPos;};
	float GetCamera(int Index) {return m_Camera[Index];};

	void SetCameraAngs(float Angs[3]);
private:
	mutable int m_CurrPos;
	int m_TotalSize;
	int m_UsedSize;

	float m_Camera[3];

	std::vector<byte> m_Data;			
};

#endif 
